其他
Pulsar IO 中 Schema 的调用流程
public class SensorReading {
public float temperature;
public SensorReading(float temperature) {
this.temperature = temperature;
}
// A no-arg constructor is required
public SensorReading() {
}
public float getTemperature() {
return temperature;
}
public void setTemperature(float temperature) {
this.temperature = temperature;
}
}
Producer<SensorReading> producer = client.newProducer(JSONSchema.of(SensorReading.class))
.topic("my-topic")
.create();
Consumer consumer = client.newConsumer(JSONSchema.of(SensorReading.class))
.topic("my-topic")
.subscriptionName("my-subscription")
.subscribe();
if (conf.getSerdeClassName() != null && !conf.getSerdeClassName().isEmpty()) {
schema = (Schema<T>) topicSchema.getSchema(topic, typeArg, conf.getSerdeClassName(), true);
} else {
schema = (Schema<T>) topicSchema.getSchema(topic, typeArg, conf.getSchemaType(), true);
}
case NONE:
return (Schema<T>) Schema.BYTES;
case AUTO_CONSUME:
case AUTO:
return (Schema<T>) Schema.AUTO_CONSUME();
case STRING:
return (Schema<T>) Schema.STRING;
case AVRO:
return AvroSchema.of(SchemaDefinition.<T>builder().withPojo(clazz).build());
case JSON:
return JSONSchema.of(SchemaDefinition.<T>builder().withPojo(clazz).build());
case KEY_VALUE:
return (Schema<T>)Schema.KV_BYTES();
case PROTOBUF:
return ProtobufSchema.ofGenericClass(clazz, Collections.emptyMap());
}
✍️Pulsar 直播 :想听什么,您说了算!